;

var user_edit_ops = {
    init: function () {
        this.eventBind();
    },
    eventBind: function () {
        $('.user_edit_wrap .save').click(function () {
            var btn_target = $(this);

            if (btn_target.hasClass('disabled')) {
                common_ops.alert('正在处理，请不要重复提交!');
                return;
            }
            var nickname_target = $('.user_edit_wrap input[name=nickname]');
            var nickname = nickname_target.val();
            var email_target = $('.user_edit_wrap input[name=email]');
            var email = email_target.val();
            if (!nickname || nickname.length < 2) {
                common_ops.tip('请输入规范的用户名称', nickname_target);
                return;
            }
            if (!email || email.length < 2) {
                common_ops.tip('请输入规范的邮箱地址', email_target);
                return;
            }
            btn_target.addClass('disabled');

            $.ajax({
                url: '/user/edit',
                data: {
                    'nickname': nickname,
                    'email': email
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    btn_target.removeClass('disabled');
                    if (data['code'] == 200) {
                        var callback = function () {
                            window.location.href = common_ops.buildUrl('/');
                        };
                        common_ops.alert('个人信息修改成功！', callback);
                    }
                    else {
                        common_ops.alert(data['msg']);
                    }
                },
                fail: function () {
                    btn_target.removeClass('disabled');
                    common_ops.alert('数据提交失败，请重试！');
                }
            });
        });
    }
};

$(function () {
    user_edit_ops.init();
});